package com.learn.threeday;

import org.apache.log4j.Logger;

import java.util.concurrent.TimeUnit;

/**
 * @author ln
 * @Description: ${todo}
 * @date 2020/12/9
 */
public class PractiseTest {

    private static final Logger logger=Logger.getLogger(PractiseTest.class);

    public static void main(String[] args) {
//        洗水壶，烧水的线程
        Thread t1=new Thread(()->{
            try {
                logger.debug("洗水壶");
                TimeUnit.SECONDS.sleep(1);
                logger.debug("烧开水");
                TimeUnit.SECONDS.sleep(5);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"t1");
        t1.start();

//        等待水烧开的过程中，洗杯子，拿茶叶的线程
        Thread t2=new Thread(()->{
            try {
                logger.debug("洗杯子");
                TimeUnit.SECONDS.sleep(2);
                logger.debug("拿茶叶");
                TimeUnit.SECONDS.sleep(1);
                t1.join();
                logger.debug("水烧好了，可以泡茶了");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"t2");
        t2.start();
    }
}
